﻿using System;
using ESRI.ArcGIS;
using ESRI.ArcGIS.esriSystem;
using System.Windows.Forms;

namespace DEMM
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {

            if (!InitializeLicense()) return;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainInterface());

        }

        private static bool InitializeLicense()
        {
            if (!RuntimeManager.Bind(ProductCode.EngineOrDesktop))
            {
                Console.WriteLine("无法绑定ArcGIS Runtime！");
                MessageBox.Show("无法绑定ArcGIS Runtime！", "DEMM Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }


            IAoInitialize aoInit = new AoInitializeClass();
            esriLicenseStatus status = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);

            if (status != esriLicenseStatus.esriLicenseCheckedOut)
            {
                Console.WriteLine("未能初始化许可证信息！");
                MessageBox.Show("未能初始化许可证信息！", "DEMM Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            if (aoInit.IsExtensionCodeAvailable(
                esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB,
                esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst) != esriLicenseStatus.esriLicenseAvailable)
            {
                Console.WriteLine("3D Analyst 扩展不可用！");
                MessageBox.Show("3D Analyst 扩展不可用！", "DEMM Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }

            Console.WriteLine("已通过验证");
            return true;
        }

    }
}
